package com.javafm;


import io.vertx.core.AbstractVerticle;
import io.vertx.core.MultiMap;
import io.vertx.core.Vertx;
import io.vertx.core.buffer.Buffer;
import io.vertx.ext.web.client.HttpResponse;
import io.vertx.ext.web.client.WebClient;


public class MainVerticle extends AbstractVerticle {
    public static void main(String[] args) {
        Vertx.vertx().deployVerticle(new MainVerticle());
    }

    @Override
    public void start() throws Exception {
        WebClient client = WebClient.create(vertx);
        //GET
        client.getAbs("http://www.baidu.com").send(ar -> {
            if (ar.succeeded()) {
                HttpResponse<Buffer> response = ar.result();
                System.out.println(response.body().toString());
            } else {
                System.out.println("发送请求失败：" + ar.cause().getMessage());
            }
        });

        // POST
        MultiMap map = MultiMap.caseInsensitiveMultiMap();
        map.add("page", "1");
        map.add("count", "5");
        client.postAbs("https://api.apiopen.top/getWangYiNews").sendForm(map, ar -> {
            if (ar.succeeded()) {
                HttpResponse<Buffer> response = ar.result();
                System.out.println(response.body().toString());
            } else {
                System.out.println("发送请求失败：" + ar.cause().getMessage());
            }
        });
    }
}
